package model;

import java.util.Collections;
import java.util.Stack;

/**
 * This class is exactly what you expect, a data structure representing a deck of cards
 * @author Phil
 *
 */
public class Deck {

        /**
         * Stack to represent a deck of cards;
         */
        private Stack<Card> cards;
        
        /**
         * Creates a deck with the cards in order of suits(H,C,S,D) then increasing rank
         */
        public Deck(){
                this.cards = new Stack<Card>();
                this.resetDeck();
        }
        
        /**
         * Remove a card from the deck and return it, if there is no more cards left to draw then return null
         * @return
         */
        public Card drawCard(){
                Card card = null;
                if(!hasCards()){
                        card = null;
                }else{
                        card = cards.pop();
                }
                return card;
        }
        
        /**
         * Check if there is any cards left in the deck
         * @return
         */
        public boolean hasCards(){
                return !cards.empty();  
        }
        
        /**
         * Collect all the cards and order them randomly
         */
        public void shuffleCards(){
                Collections.shuffle(cards);
        }
        
        /**
         * Collect all 52 cards and put them into the deck ordered
         */
        public void resetDeck(){
                cards.removeAllElements();
                for(int i=0; i<4; i++){ //loop through the suits
                        for(int j=0; j<13; j++){ //loop through the ranks
                                Card card = new Card(j, i);
                                cards.push(card);
                        }
                }
        }
}